package actions.admintool;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.ResultPath;

import com.opensymphony.xwork2.ActionSupport;

import dao.BarRepository;
import domain.Bar;


@Namespace("/")
@ResultPath(value="/")
public class BarDetailAction extends ActionSupport {

	public static final long serialVersionUID = 1L;
	private BarRepository br = new BarRepository();
	private Bar bar;
	private String id;

	public BarDetailAction() {}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Action(value="barDetail", results={
			@Result(name="success",location="pages/admintool/bar_detail.jsp"),
			@Result(name="error",location="pages/admintool/bar_detail_error.jsp")
	})
	
	public String execute() {		
		try {
			bar = br.getById(Long.parseLong(id));
			return SUCCESS;
		} catch (Exception e) {			
			return ERROR; 
		}
	}

	public Bar getBar() {
		return bar;
	}

	public void setBar(Bar bar) {
		this.bar = bar;
	}	

}
